package com.dzh.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dzh.pojo.Loans;
import com.dzh.pojo.Message;
import com.dzh.service.AppService;
import com.dzh.service.LoansService;
import com.dzh.service.MessageService;
import com.dzh.vo.SigninRecord;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.jsonwebtoken.Jwts;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/personage")
public class PersonageController {

    @Resource
    private AppService appService;
    @Autowired
    private LoansService loansService;

    @Autowired
    private MessageService messageService;

    //查询贷款信息
    @PostMapping("/loanslist")
    public List<Loans> loansList(HttpServletResponse response){
        String token = response.getHeader("token");
        Claims abcdefghijklmnopqrstuvwxyz = Jwts.parser().setSigningKey("abcdefghijklmnopqrstuvwxyz").parseClaimsJws(token).getBody();
        Object user_id = abcdefghijklmnopqrstuvwxyz.get("user_id");
        QueryWrapper<Loans> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid",user_id);
        List<Loans> list = loansService.list(queryWrapper);
        return list;
    }

    //还款信息
    @PostMapping("/messagelist")
    public List<Message> messageList(@RequestParam("lid") Integer lid){
        QueryWrapper<Message> wrapper = new QueryWrapper<>();
        wrapper.eq("lid",lid);
        List<Message> list = messageService.list(wrapper);
        return list;
    }

    //查看签到记录
    @PostMapping("/signinlist")
    public List<SigninRecord> signinRecordList(HttpServletResponse response){
//        String token = response.getHeader("token");
//        Claims abcdefghijklmnopqrstuvwxyz = Jwts.parser().setSigningKey("abcdefghijklmnopqrstuvwxyz").parseClaimsJws(token).getBody();
//        Object user_id = abcdefghijklmnopqrstuvwxyz.get("user_id");
        List<SigninRecord> signinList = appService.signinRecordList(1);
        return signinList;
    }
}
